<?php
/**
 * 会员中心显示控制器
 * UserModel:LLW
 * Date:2020-03-12
 */

namespace app\caidongweb\controller;
use app\caidongweb\model\MoneyLogModel;
use app\caidongweb\model\UserLeverModel;
use app\caidongweb\model\UserLogModel;
use app\caidongweb\model\UserModel;
use think\Db;
use think\Request;
class User extends BaseController
{

    public function __construct(Request $request)
    {
        parent::__construct();
        $this->use = new UserModel();
        $this->mon = new MoneyLogModel();
        $this->log = new UserLogModel();
    }

    /******************************** 会员列表相关 ***************************************/
    /**
     * 会员列表
     * @return \think\response\View
     */
    public function userList()
    {
        $list = $this->use->getList();
        $count = tableCount('user');
        $this->assign('count',$count);
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return view();
    }

    /**
     * 伪会员
     * @return \think\response\View
     */
    public function delList()
    {
        $list = $this->use->getDelList();
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return view();
    }

    /**
     * 获取个人信息
     * @return \think\response\View
     */
    public function userFind()
    {
        $uid = input('uid');
        $find = $this->use->getFind($uid);
        $this->assign('find',$find);
        return view();
    }

    /**
     * 会员添加
     * @return array|\think\response\View
     */
    public function userAdd()
    {
        if(input('post.')){
            $res = $this->use->getAdd();
            return $res;
        }else{
            return view();
        }
    }

    /**
     * 编辑个人信息
     * @return mixed
     */
    public function userEdit()
    {
        $res = $this->use->getEdit();
        return $res;
    }

    /**
     * 删除用户
     * @return array
     */
    public function userDels()
    {
        $res = $this->use->getDel();
        return $res;
    }

    /**
     * 个人推荐码
     * @return array
     */
    public function code()
    {
        $uid = input('uid');
        $user = $this->use->getFind($uid);
        $code = verificationCode($user['us_phone']);
        if($code){
            $list = db('user')->where('us_uid',$uid)->update(['us_img_code'=>$code]);
            $status = $this->returnData(1,'成功');
        }else{
            $status = $this->returnData(-1,'失败');
        }
        return $status;
    }

    /**
     * 提交账户变动信息
     * @return array|\think\response\View
     */
    public function userPoints()
    {
        if(input('post.')){
            $res = $this->use->getPoints();
            return $res;
        }else{
            return view();
        }
    }

    /**
     * 获取个人积分
     * @return array
     */
    public function pointsFind()
    {
        $res = $this->use->getPonFind();
        return $res;
    }

    /******************************** 资金明细 ***************************************/
    /**
     * 首页
     * @return \think\response\View
     */
    public function pointsList()
    {
        $list = $this->mon->getList();
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return view();
    }

    /******************************** 等级相关 ***************************************/
    /**
     * 首页
     * @return \think\response\View
     */
    public function leverList()
    {
        $list = $this->usl->getList();
        $this->assign('list',$list);
        return view();
    }

    /**
     * 添加修改
     * @return array|\think\response\View
     */
    public function leverAddEdit()
    {
        $id = input('id',null);
        if(input('post.')){
            $res = $this->usl->getAddEdit();
            return $res;
        }else{
            $find = Db::name('user_lever')->where('ue_id',$id)->find();
            $this->assign('find',$find);
            return view();
        }
    }
    /******************************** 会员消息相关 ***************************************/
    /**
     * 会员消息
     * @return \think\response\View
     */
    public function userLog()
    {
        $list = $this->log->getList();
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return view();
    }

    /**
     * 发送用户消息
     * @return array|\think\response\View
     */
    public function logAdd()
    {
        if(input('post.')){
            $res = $this->log->getAdd();
            return $res;
        }else{
            return view();
        }
    }
    /**
     * 消息删除
     * @return array
     */
    public function userDel()
    {
        $id = input('id');
        $res = $this->del('user_log',['ul_id'=>$id]);
        if($res){
            return $this->returnData(1,'删除成功');
        }else{
            return $this->returnData(-1,'哎呀！网络好像在开小差');
        }
    }
}